<template>
  <div class="content-share-table">
    <div
      :class="curActiveIndex === i ? 'chat-item active' : 'chat-item'"
      v-for="(item, i) in tableData"
      :key="i"
      @click="itemClick(item, i)">
      <el-avatar shape="square" class="avatar">{{ item.name.substr(0, 1) }}</el-avatar>
      <div class="content" v-if="curType === 'chat'">
        <div class="info">
          <div class="name">{{ item.name }}</div>
          <div class="word" :title="item.chatContent">{{ item.chatContent }}</div>
        </div>
        <div class="time">{{ item.chatTime }}</div>
      </div>
      <div class="content-friends" v-else-if="curType === 'friends'">
        {{ item.name }}
        <i class="el-icon-more icon" title="查看详细信息" @click="viewFriendInfo(item.name)"></i>
      </div>
      <div class="content-friends" v-else-if="curType === 'groups'">
        {{ item.name }}
        <i class="el-icon-more icon" title="查看群成员" @click="viewGroupMember(item.name)"></i>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ContentShareTable',
  props: {
    tableData: {
      type: Array,
      dafault: () => []
    },
    curType: {
      type: String,
      default: () => 'chat'
    }
  },
  data() {
    return {
      curActiveIndex: '',
    }
  },
  methods: {
    itemClick(item, i) {
      this.curActiveIndex = i;
      item.id = i;
      item.curType = this.curType;
      this.$bus.$emit('chatClick', item);
    },
    viewGroupMember(name) {
      this.$bus.$emit('viewGroupMember', name);
    },
    createGroup() {
      this.$bus.$emit('createGroup');
    },
    viewFriendInfo(name) {
      this.$bus.$emit('viewFriendInfo', name);
    }
  }
}
</script>

<style lang="less">
.content-share-table {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  float: left;

  .chat-item {
    display: flex;
    justify-content: space-between;
    padding: 7px 8px;
    width: 100%;
    height: 60px;
    box-sizing: border-box;
    cursor: pointer;

    &:hover, &.active {
      background-color: #eaeef0;
    }

    .avatar {
      width: 45px;
      height: 45px;

      &.el-avatar {
        background: #0a99ff;
        line-height: 45px;
      }
    }

    .content {
      width: calc(100% - 55px);
      height: 100%;
      display: flex;
      justify-content: space-between;
      background-color: transparent;

      .info {
        width: calc(100% - 45px);
        height: 45px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;

        div {
          height: 22.5px;
          width: 100%;
          font-size: 14px;
          color: #000000;
        }

        .word {
          color: #b6b6b6;
          font-size: 12px;
          line-height: 30px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }

      .time {
        width: 45px;
        height: 45px;
        line-height: 45px;
        text-align: right;
        color: #999999;
        font-size: 12px;
      }
    }

    .content-friends {
      width: calc(100% - 55px);
      height: 100%;
      text-align: left;
      line-height: 45px;

      .icon {
        font-size: 18px;
        float: right;
        line-height: 45px;
        color: #999999;
      }
    }
  }
}
</style>